package kr.saeildamil.androidstudy.ch06;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;

public class SetParameterEx extends Activity {
	Button mLeft, mRight;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setparameter);
		
		mLeft = (Button) findViewById(R.id.setparameter_left_btn);
		mRight = (Button) findViewById(R.id.setparameter_right_btn);
		
		mLeft.setOnClickListener(listener);
		mRight.setOnClickListener(listener);
		
	}
	
	View.OnClickListener listener = new OnClickListener() {
		public void onClick(View v) {
			if(v.getId() == R.id.setparameter_left_btn) {
				setParam(1,3);
			}else {
				setParam(3,1);
			}
			
		}
	};

	protected void setParam(int left, int right) {
		LinearLayout.LayoutParams lParams = (LayoutParams) mLeft.getLayoutParams();
		LinearLayout.LayoutParams rParams = (LayoutParams) mRight.getLayoutParams();
		
		String str = "Left Button Weight : " + lParams.weight + 
				"\nRight Button Weight : " + rParams.weight;
		
		Toast.makeText(this, str, Toast.LENGTH_LONG).show();
		
		lParams.weight = left;
		rParams.weight = right;
		
		mLeft.setLayoutParams(lParams);
		mRight.setLayoutParams(rParams);
		
		str = "Left Button Weight : " + lParams.weight + 
				"\nRight Button Weight : " + rParams.weight;
		
		Toast.makeText(this, str, Toast.LENGTH_LONG).show();
		
	}
	
}
